/**
 * item contrller
 * add by tangjiannan
 */
package com.crm.business.web.svcpkg.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crm.business.web.cust.controller.CustomerController;
import com.crm.business.web.svcpkg.service.SvcItemService;
import com.crm.common.web.controller.WebCommonController;

/**
 * 服务项操作类
 * 
 * @author tangjiannan
 *
 */
@Controller("svcpkg_svcitemController")
public class SvcItemController extends WebCommonController {
    /** Logger */
    private static final Logger LOG = Logger
            .getLogger(CustomerController.class);
    /** Main Service */
    @Resource(name = "svcpkg_svcItemService")
    private SvcItemService service = null;

    /**
     * Show item Main Page
     * 
     * @return main page
     */
    @RequestMapping("show_svcitem.shtm")
    public ModelAndView show(HttpServletRequest req) {
        ModelAndView mv = createOpenPageMV(req);
        mv.setViewName("svcpkg/p00_svcitem_main.jsp");
        return mv;
    }

    /**
     * Add svcitem
     * 
     * @param req HttpServletRequest
     * @param resp HttpServletResponse
     */
    @RequestMapping("svcitem/add.shtm")
    public void add(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("add svcitem info beging...");

        // request parameters
        Map<String, Object> params = getReqParams(req);
        boolean msg = this.service.addItem(params);

        Map<String, Object> output = new HashMap<String, Object>();
        output.put("success", msg);
        outputJSON(resp, output);

        LOG.info("add svcitem info end...");
    }

    /**
     * query svcitems
     * 
     * @param req HttpServletRequest
     * @param resp HttpServletResponse
     */
    @RequestMapping("svcitem/query.shtm")
    public void query(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("query svcitems info beging...");

        // request parameters
        Map<String, Object> params = getReqParams(req);

        // query
        this.service.doQuery(params);

        Map<String, Object> output = getDefaultResult();
        output.put("svcitems", params.get("svcitems"));
        outputJSON(resp, output);

        LOG.info("query svcitems info finshed.");
    }

    @RequestMapping("svcitem/loadmodel.shtm")
    public void queryModel(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("query svcitem info beging...");
        // request parameters
        Map<String, Object> params = getReqParams(req);

        // query
        this.service.doQueryModel(params);

        Map<String, Object> output = getDefaultResult();
        output.put("success", "true");
        output.put("data", params.get("svcitem"));
        outputJSON(resp, output);
        LOG.info("query svcitem info finshed.");
    }

    @RequestMapping("svcitem/delitem.shtm")
    public void del(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("delete svcitem info beging...");

        // request parameters
        Map<String, Object> params = getReqParams(req);
        
        // query
        this.service.doDelItem(params);

        Map<String, Object> output = getDefaultResult();
        outputJSON(resp, output);

        LOG.info("delete svcitem info finshed.");
    }

    @RequestMapping("svcitem/updateitem.shtm")
    public void update(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("update svcitem info beging...");

        // request parameters
        Map<String, Object> params = getReqParams(req);

        // query
        this.service.doUpdateItem(params);

        Map<String, Object> output = getDefaultResult();
        outputJSON(resp, output);

        LOG.info("update svcitem info finshed.");
    }

}
